<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 7/25/24
 * Time: 10:43 AM
 */


namespace app\adminapi\controller\media;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\media\MediaAccountLists;
use app\adminapi\logic\media\MediaAccountLogic;



/**
 * MediaAccount控制器
 * Class MediaAccountController
 * @package app\adminapi\controller
 */
class MediaAccountController extends BaseAdminController
{


    /**
     * @notes 获取列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/04 14:40
     */
    public function lists()
    {
        return $this->dataLists(new MediaAccountLists());
    }



    /**
     * 通过媒体获取所有账户信息
     *
     * @return \think\response\Json
     */
    public function getAllAccountByMedia()
    {
        return $this->dataLists(new MediaAccountLists('all'));
    }


    /**
     * 获取媒体授权账户链接
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getEmpowerUrl()
    {
        $params             = $this->request->post();
        $params['admin_id'] = $this->adminId;
        $result             = MediaAccountLogic::getEmpowerUrl($params);
        if (is_string($result)) {

            return $this->data(['empower_url' => $result]);
        }

        return $result ? $this->success('授权成功', [], 1, 1) : $this->fail('授权失败');
    }


    /**
     * 绑定推广ID
     *
     * @return \think\response\Json
     */
    public function bindPromotion()
    {
        $id              = $this->request->get('id', 0);
        $promotionLinkId = $this->request->get('promotion_link_id', 0);

        return MediaAccountLogic::bindPromotion($id, $promotionLinkId) ?
            $this->success('绑定成功') : $this->fail('绑定失败');
    }


    /**
     * 绑定事件源ID
     *
     * @return \think\response\Json
     */
    public function bindSrc()
    {
        $id    = $this->request->get('id', 0);
        $srcId = $this->request->get('src_id', 0);

        return MediaAccountLogic::bindSrc($id, $srcId) ?
            $this->success('绑定成功') : $this->fail('绑定失败');
    }


    /**
     * 设置项目组
     *
     * @return \think\response\Json
     */
    public function setTeam()
    {
        $accountIds = $this->request->post('account_ids', []);
        $teamId     = $this->request->post('team_id', 0);

        return MediaAccountLogic::setTeam($teamId, $accountIds) ?
            $this->success('设置项目组成功') : $this->fail('设置项目组失败');
    }
}
